package com.yu.crm.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yu.crm.domain.pojo.Shift;
import com.yu.crm.domain.pojo.Ticketinfo;
import com.yu.crm.service.impl.ShiftService;
import com.yxzz.common.helper.valid.ValidatorHelpers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zds
 * @since 2021-03-22
 */
@Api(tags = "班次管理")
@RestController
@RequestMapping("/shift")
public class ShiftController {

    @Autowired
    private ShiftService shiftService;

    @ApiOperation("根据id批量删除")
    @DeleteMapping("/remove-batch-by-id")
    public void removeBatchById(@RequestParam("ids") String ids){
        shiftService.deleteByIds(ids);
    }

    @ApiOperation("根据id删除车站")
    @DeleteMapping("/remove-by-id/{id}")
    public void removeById(@PathVariable Long id){
        shiftService.removeById(id);
    }

    @ApiOperation(value = "保存或修改")
    @PostMapping(value = "/save")
    public boolean save(@RequestBody Shift shift){
        return shiftService.saveOrUpdate(shift);
    }

    /**
     * 通过班次主键查询班次详情
     * @param id 班次主键
     * @return
     */
    @ApiOperation(value = "通过班次主键查询班次详情")
    @GetMapping(value = "/info-by-id")
    public Shift infoById(@RequestParam("id") Long id){
        ValidatorHelpers.notEmpty(id, "班次编号不能为空");
        return shiftService.infoById(id);
    }

    @ApiOperation(value = "查询列表导出用")
    @GetMapping(value = "/pageList")
    public List<Shift> getPageList(@RequestParam(required = false) String stationName,
                                @RequestParam(required = false) String condition) {
        return shiftService.getPage(stationName, condition);
    }

    @ApiOperation(value = "查询列表")
    @GetMapping(value = "/page")
    public IPage<Shift> getPage(Page<Shift> page,
                                @RequestParam(required = false) String stationName,
                                @RequestParam(required = false) String condition) {
        return shiftService.getPage(page, stationName, condition);
    }

}

